package com.donquijote.controller;

import com.donquijote.config.TimerMethodInterceptor;
import com.donquijote.service.UserService;
import net.sf.cglib.proxy.Enhancer;

/**
 * @author 421527548@qq.com
 * @version V1.0
 * @title
 * @description
 * @date 2022-11-27 10:20
 */
public class UserController {

    public static void main(String[] args) {
        //创建代码字节码增强器
        Enhancer enhancer = new Enhancer();
        //cglib需要继承的类
        enhancer.setSuperclass(UserService.class);
        //设置回调接口
        enhancer.setCallback(new TimerMethodInterceptor());
        //生成源码，编译class 加载到JVM，并且创建代理对象
        UserService userService = (UserService) enhancer.create();
        userService.login();
        userService.logout();

    }
}
